import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const routes = [
    {
        path: '*',
        redirect: '/findJob'
    },
    {
        name: 'main',
        component: () => import('./view/main'),
        meta: {
            title: '速派建筑人才网'
        },
        children: [
            {
                path: '/findJob',
                component: () => import('./view/findJob')
            },
            {
                path: '/findWorker',
                component: () => import('./view/findWorker')
            },
            {
                path: '/user',
                component: () => import('./view/user')
            }
        ]
    },
    {
        name: 'back',
        component: () => import('./view/back'),
        meta: {
            title: '速派建筑人才网'
        },
        children: [
            {
                path: '/workerAdd',
                component: () => import('./view/mine/workerAdd')
            },
            {
                path: '/companyAdd',
                component: () => import('./view/mine/companyAdd')
            },
            {
                path: '/jobAdd',
                component: () => import('./view/mine/jobAdd')
            },
            {
                path: '/jobInfo',
                component: () => import('./view/mine/jobInfo')
            },
            {
                path: '/workerInfo',
                component: () => import('./view/mine/workerInfo')
            },
            {
                path: '/checkWorkerInfo',
                component: () => import('./view/mine/checkWorkerInfo'),
            },
            {
                path: '/checkWorkerInfo/editWorkerInfo',
                name: 'editWorkerInfo',
                component: () => import('./view/mine/editWorkerInfo')
            },
            {
                path: '/checkJobInfo',
                component: () => import('./view/mine/checkJobInfo'),
            },
            {
                path: '/checkJobInfo/editJobInfo',
                name: 'editJobInfo',
                component: () => import('./view/mine/editJobInfo')
            },
        ]
    },
];

// add route path
routes.forEach(route => {
    route.path = route.path || '/' + (route.name || '');
});

const router = new Router({routes});

router.beforeEach((to, from, next) => {
    const title = to.meta && to.meta.title;
    if (title) {
        document.title = title;
    }
    next();
});

export {
    router
};
